/**
 * author: XGP
 * date: 2018/07/25
 * des: 人员招聘-参数设置
 *
 */
import {
  getruleAll
} from './api.js'

// setListSetting,ruleListSetting
export const ruleListSetting = [{
  field: 'ruleId',
  title: '规则编号',
  type: 'text',
  hideDetail: true,
  hideEdit: true,
  isHiden: true
},
{
  field: 'ruleName',
  title: '规则名称',
  type: 'text',
  searchable: true
},
{
  field: 'attendRule',
  title: '考勤规则',
  type: 'selected',
  searchable: true,
  customText: (item) => {
    switch (item.attendRule) {
      case 'A':
        return '不用打卡'
      case 'B':
        return '一天两卡'
      case 'C':
        return '一天四卡'
      case 'D':
        return '一天六卡'
    }
  },
  options: [{
    name: '不用打卡',
    value: 'A'
  },
  {
    name: '一天两卡',
    value: 'B'
  },
  {
    name: '一天四卡',
    value: 'C'
  },
  {
    name: '一天六卡',
    value: 'D'
  }
  ]
},
{
  field: 'elasticFlag',
  title: '是否弹性上班',
  customText: (item) => {
    switch (item.elasticFlag) {
      case '0':
        return '否'
      case '1':
        return '是'
    }
  },
  type: 'radio',
  optional: [{
    name: '非弹性上班',
    value: '0'
  }, {
    name: '弹性上班制',
    value: '1'
  }]
},
{
  field: 'exemptTime',
  title: '豁免时间',
  type: 'text'
},
{
  field: 'abstmLimit',
  title: '迟到早退时间',
  type: 'text'
},
{
  field: 'punchTime1',
  title: '上班时间',
  type: 'time'
},

{
  field: 'punchTime2',
  title: '下班时间',
  type: 'time'
}, {
  field: 'isValid',
  title: '是否有效',
  type: 'radio',
  optional: [{
    name: '有效',
    value: '1'
  }, {
    name: '无效',
    value: '2'
  }],
  customText: (item) => {
    switch (item.isValid) {
      case '2':
        return '否'
      case '1':
        return '是'
    }
  },
}, {
  field: 'restTime',
  title: '休息时长',
  type: 'text'
},


]

export const setListSetting = [{
  field: 'id',
  title: '规则id',
  type: 'text',
  disableEdit: true,
  hideEdit: true
},
{
  field: 'addr',
  title: '工作地址',
  type: 'selected',
  isParams: true, // 默认为false，当isParams 为true 时，下拉数据为参数类型，
  paramsId: 'WORKPLACE',
  searchable: true
}, {
  field: 'ruleName',
  title: '规则名称',
  type: 'text',
  disableEdit: true,
  hideEdit: true
},

{
  field: 'ruleId',
  title: '规则名称',
  type: 'selected',
  isHiden: true,
  hideDetail: true,
  options: [],
  searchable: true,
  init: (form, item) => {
    const options = []
    getruleAll().then(response => {
      if (response.success) {
        response.list.forEach(v => {
          const a = {
            name: v.ruleName,
            value: v.ruleId
          }
          options.push(a)
        })
      }
      setListSetting.forEach(v => {
        if (v.field === 'ruleId') {
          v.options = options
        }
      })
    })
  },
  itemChange: (form, b, c) => {
    const options = []
    getruleAll().then(response => {
      if (response.success) {
        response.list.forEach(v => {
          const a = {
            name: v.ruleName,
            value: v.ruleId
          }
          options.push(a)
        })
      }
      setListSetting.forEach(v => {
        if (v.field === 'ruleId') {
          v.options = options
        }
      })
    })
  }
}

]



export const setEditSetting = [{
  field: 'id',
  title: '规则id',
  type: 'text',
  disableEdit: true,
  hideEdit: true
},
{
  field: 'addr',
  title: '工作地址',
  type: 'selected',
  isParams: true, // 默认为false，当isParams 为true 时，下拉数据为参数类型，
  paramsId: 'WORKPLACE',
  disableEdit: true,
},
{
  field: 'ruleId',
  title: '规则名称',
  type: 'selected',
  isHiden: true,
  hideDetail: true,
  options: [],
  init: (form, item) => {
    const options = []
    getruleAll().then(response => {
      if (response.success) {
        response.list.forEach(v => {
          const a = {
            name: v.ruleName,
            value: v.ruleId
          }
          options.push(a)
        })
      }
      setEditSetting.forEach(v => {
        if (v.field === 'ruleId') {
          v.options = options
        }
      })
    })
  },

  itemChange: (form, b, c) => {
    const options = []
    getruleAll().then(response => {
      if (response.success) {
        response.list.forEach(v => {
          const a = {
            name: v.ruleName,
            value: v.ruleId
          }
          options.push(a)
        })
      }

      setEditSetting.forEach(v => {
        if (v.field === 'ruleId') {
          v.options = options
        }
      })
    })
  }
}
]
